package com.example.card.implemention;

import com.example.card.domain.card.CardClassification;

import java.time.LocalDate;

public class BlueCardClassification extends CardClassification {


    private final LimitConsumptionDate limitConsumptionDate;

    public BlueCardClassification() {
        this.limitConsumptionDate = reset();
    }

    @Override
    public int calculate(PayCheck pc) {
        checkLimit(pc.getAmount());



        return pc.getAmount();
    }

    LimitConsumptionDate reset() {
        LocalDate now = LocalDate.now();
        return new LimitConsumptionDate(now, now, 1000_00);
    }

    private void checkLimit(Integer amount) {
        if (!limitConsumptionDate.inPeriod()) {
            reset();
        }
        if (limitConsumptionDate.outLimit(amount)) {
            throw new RuntimeException("改卡超出当日限额");
        }
    }


}
